<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/7/14
 * Time: 10:50
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Sailing extends Base
{
    /**
     * 赛事列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $match_start_time = input('match_start_time');
            $match_end_time = input('match_end_time');
            $apply_start_time = input('apply_start_time');
            $apply_end_time = input('apply_end_time');
            $keyword = trim(input('keyword'), ' ');
            $match_status = input('match_status');
            $where['match_cate'] = 1;
            // 比赛时间
            if(isset($match_start_time) && $match_start_time != '' && isset($match_end_time) && $match_end_time != ''){
                $where['match_start_time'] = ['>=', $match_start_time];
                $where['match_end_time'] = ['<=', $match_end_time];
            }
            if(isset($match_start_time) && $match_start_time != '' && isset($match_end_time) && $match_end_time == ''){
                $where['match_start_time'] = ['>=', $match_start_time];
            }
            if(isset($match_start_time) && $match_start_time == '' && isset($match_end_time) && $match_end_time != ''){
                $where['match_end_time'] = ['<=', $match_end_time];
            }
            // 比赛报名时间
            if(isset($apply_start_time) && $apply_start_time != '' && isset($apply_end_time) && $apply_end_time != ''){
                $where['match_apply_start_time'] = ['>=', $apply_start_time];
                $where['match_apply_end_time'] = ['<=', $apply_end_time];
            }
            if(isset($apply_start_time) && $apply_start_time != '' && isset($apply_end_time) && $apply_end_time == ''){
                $where['match_apply_start_time'] = ['>=', $apply_start_time];
            }
            if(isset($apply_start_time) && $apply_start_time == '' && isset($apply_end_time) && $apply_end_time != ''){
                $where['match_apply_end_time'] = ['<=', $apply_end_time];
            }
            // 关键字
            if(isset($keyword) && $keyword != ''){
                $where['match_id|match_title|com_name'] = ['like', '%' . $keyword . '%'];
            }
            // 赛事状态
            if(isset($match_status) && $match_status != ''){
                $where['match_status'] = $match_status;
            }
            
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match')
                ->join('up_u_user', 'match_zong_user_id = user_id', 'left')
                ->join('up_committee', 'com_id = match_committee_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match')
                ->join('up_u_user', 'match_zong_user_id = user_id', 'left')
                ->join('up_committee', 'com_id = match_committee_id', 'left')
                ->field('match_id, match_title, match_addr, match_apply_start_time, match_apply_end_time, 
                match_start_time, match_end_time, match_create_time, match_boat_id, match_status, 
                match_apply_num, com_name, match_zong_user_id, match_zhong_user_id, match_cancel_reason, 
                match_bianpai_user_id, match_zhuren_user_id, match_mishu_user_id, match_hexiao_user_id, match_cate, 
                user_username')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('match_create_time desc')
                ->select();
            
            foreach($lists as $k => $v){
                // 赛事时间
                $match_time = date('Y-m-d H:i', strtotime($v['match_start_time'])) . '~' . date('Y-m-d H:i', strtotime($v['match_end_time']));
                $lists[$k]['match_time'] = $match_time;
                // 赛事报名时间
                $match_apply_time = date('Y-m-d H:i', strtotime($v['match_apply_start_time'])) . '~' . date('Y-m-d H:i', strtotime($v['match_apply_end_time']));
                $lists[$k]['match_apply_time'] = $match_apply_time;
                // 船型
                $boat = Db::table('up_boat')
                    ->where('boat_id', 'IN', $v['match_boat_id'])
                    ->column('boat_name');
                $lists[$k]['boat_name'] = implode(',', $boat);
                // 终点裁判
                $zhong = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_zhong_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['zhong'] = implode(',', $zhong);
                // 编排长
                $bianpai = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_bianpai_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['bianpai'] = implode(',', $bianpai);
                // 仲裁主任
                $zhuren = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_zhuren_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['zhuren'] = implode(',', $zhuren);
                // 仲裁秘书
                $mishu = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_mishu_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['mishu'] = implode(',', $mishu);
                // 竞赛检录
                $hexiao = Db::table('up_u_user')
                    ->where('user_id', 'IN', trim($v['match_hexiao_user_id'], ','))
                    ->column('user_username');
                $lists[$k]['hexiao'] = implode(',', $hexiao);
                // 组别&报名人数
                $group = Db::table('up_match_apply_group')
                    ->join('up_match_group', 'mg_id = mag_group_id', 'left')
                    ->where('mag_match_id', $v['match_id'])
                    ->field('mg_name, mag_already_num')
                    ->select();
                $lists[$k]['group_name'] = implode(',', array_column($group, 'mg_name'));
                $lists[$k]['apply_num'] = array_sum(array_column($group, 'mag_already_num'));
            }
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        
        return $this->fetch();
    }
    
    /**
     * 生活信息
     * @return mixed|\think\response\Json
     */
    public function matchLife(){
        if(request()->isAjax ()){
            $where['ml_match_id'] = session('match_id');
        
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_life')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_life')
                ->field('ml_id, ml_type')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('ml_id desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && !empty($match_id)){
            session('match_id', $match_id);
        }
        return $this->fetch('sailing/matchlife');
    }
    
    /**
     * 生活信息详情
     * @return mixed
     */
    public function lifeDetail(){
        $ml_id = input('ml_id');
        $life = Db::table('up_match_life')
            ->field('ml_content')
            ->where('ml_id', $ml_id)
            ->find();
        $this->assign('life', $life);
        return $this->fetch('sailing/lifedetail');
    }
    
    /**
     * 生活信息附件
     * @return mixed|\think\response\Json
     */
    public function lifeFiles(){
        if(request()->isAjax ()){
            $where['mli_life_id'] = session('ml_id');
            
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_life_info')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_life_info')
                ->field('mli_id, mli_name, mli_url, mli_dis')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mli_id desc')
                ->select();
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $ml_id = input('ml_id');
        if(isset($ml_id) && !empty($ml_id)){
            session('ml_id', $ml_id);
        }
        return $this->fetch('sailing/lifefiles');
    }
    
    /**
     * 官方公告
     * @return mixed|\think\response\Json
     */
    public function matchGf(){
        if(request()->isAjax ()){
            $where['mgf_match_id'] = session('match_id');
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_gf')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_gf')
                ->field('mgf_id, mgf_title, mgf_intro, mgf_time')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mgf_time desc')
                ->select();
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && !empty($match_id)){
            session('match_id', $match_id);
        }
        return $this->fetch('sailing/matchgf');
    }
    
    /**
     * 官方公告文件
     * @return mixed|\think\response\Json
     */
    public function gfFiles(){
        if(request()->isAjax ()){
            $where['mgfff_gf_id'] = session('mgf_id');
            
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_gf_files')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_gf_files')
                ->field('mgff_id, mgff_file_url, mgff_file_name, mgff_file_bmp')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mgff_id desc')
                ->select();
            
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $mgf_id = input('mgf_id');
        if(isset($mgf_id) && !empty($mgf_id)){
            session('mgf_id', $mgf_id);
        }
        return $this->fetch('sailing/gffiles');
    }
    
    /**
     * 官方公告详情
     * @return mixed|\think\response\Json
     */
    public function gfDetail(){
        $mgf_id = input('mgf_id');
        $gf = Db::table('up_match_gf')
            ->field('mgf_title, mgf_intro')
            ->where('mgf_id', $mgf_id)
            ->find();
        $this->assign([
            'gf' => $gf,
            'mgf_id' => $mgf_id
        ]);
        return $this->fetch('sailing/gfdetail');
    }
    
    /**
     * 赛事照片
     * @return mixed|\think\response\Json
     */
    public function matchImage(){
        if(request()->isAjax ()){
            $mi_name = trim(input('mi_name'), ' ');
            $mi_paishe_name = trim(input('mi_paishe_name'), ' ');
            $where['mi_match_id'] = session('match_id');
            if(isset($mi_name) && $mi_name != ''){
                $where['mi_name'] = ['like', '%' . $mi_name . '%'];
            }
            if(isset($mi_paishe_name) && $mi_paishe_name != ''){
                $where['mi_paishe_name'] = ['like', '%' . $mi_paishe_name . '%'];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_images')
                ->join('up_match', 'match_id = mi_match_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_images')
                ->join('up_match', 'match_id = mi_match_id', 'left')
                ->field('mi_id, mi_url, mi_name, mi_paishe_name, mi_paishe_time, mi_price, mi_create_time, 
                match_title')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mi_create_time desc')
                ->select();
            if($lists){
                foreach($lists as $k => $v){
                    $lists[$k]['mi_paishe_time'] = date('Y-m-d H:i', strtotime($v['mi_paishe_time']));
                }
            }
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && $match_id != ''){
            session('match_id', $match_id);
        }
        return $this->fetch('sailing/matchimage');
    }
    
    /**
     * 赛事视频
     * @return mixed|\think\response\Json
     */
    public function matchVideo(){
        if(request()->isAjax ()){
            $mv_video_name = trim(input('mv_video_name'), ' ');
            $where['mv_match_id'] = session('match_id');
            if(isset($mv_video_name) && $mv_video_name != ''){
                $where['mv_video_name'] = ['like', '%' . $mv_video_name . '%'];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('match_video')
                ->join('up_match', 'match_id = mv_match_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('match_video')
                ->join('up_match', 'match_id = mv_match_id', 'left')
                ->field('mv_id, mv_video_url, mv_video_name, mv_time, match_title')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('mv_time desc')
                ->select();
        
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $match_id = input('match_id');
        if(isset($match_id) && $match_id != ''){
            session('match_id', $match_id);
        }
        return $this->fetch('sailing/matchvideo');
    }
    
    /**
     * 临时成绩
     * @return mixed|\think\response\Json
     */
    public function lsMark(){
        $match_id = input('match_id');
        if(isset($match_id) && $match_id != ''){
            session('match_id', $match_id);
        }
        
        $match = Db::table('up_match')
            ->where('match_id', session('match_id'))
            ->field('match_lunci')
            ->find();
        $group = Db::table('up_match_apply_group')
            ->join('up_match_group', 'mg_id = mag_group_id', 'left')
            ->where('mag_match_id', session('match_id'))
            ->field('mg_id, mg_name')
            ->select();
        $lunci = range(1, $match['match_lunci']);
    
        if(request()->isAjax ()){
            $group_id = input('group_id'); //  组
            $lc_id = input('lc_id'); // 轮次
            $where['umd.match_id'] = session('match_id');
            $where['umd.flag'] = 3;
            if(isset($group_id) && $group_id != ''){
                $where['umd.level_id'] = $group_id;
            }else{
                $where['umd.level_id'] = $group[0]['mg_id'];
            }
            if(isset($lc_id) && $lc_id != ''){
                $where['umd.turn'] = $lc_id;
            }else{
                $where['umd.turn'] = $lunci[0];
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->join('up_u_user uuu', 'uuu.user_id = umar.user_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $count2 = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->join('up_u_user uuu', 'uuu.user_id = umar.user_id', 'left')
                ->where($where)
                ->column('umar.id');// 获取总条数
            $lists = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->join('up_u_user uuu', 'uuu.user_id = umar.user_id', 'left')
                ->field('umar.id, umd.match_id, umar.temp_score, umar.sensor_id, ls_status, umd.turn, 
                uuu.user_phone, user_real_name, user_create_id, uuu.user_id')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('umd.turn asc, temp_score asc')
                ->select();
            foreach($lists as $k => $v){
                // 名次
                $lists[$k]['mc'] = $k + 1;
                // 报名信息
//                if($v['sensor_id']){
//                    $sensor = explode('_', $v['sensor_id']);
//                    $user = Db::table('up_u_user')
//                        ->where('user_id', $sensor[1])
//                        ->field('user_phone, user_real_name, user_create_id')
//                        ->find();
                    $apply = Db::table('up_match_apply_info')
                        ->where('ma_user_id', $v['user_id'])
                        ->where('ma_match_id', $v['match_id'])
                        ->field('ma_fan_code')
                        ->find();
                    $lists[$k]['fan_code'] = $apply['ma_fan_code'];
//                    $lists[$k]['user_phone'] = $user['user_phone'];
//                    $lists[$k]['user_real_name'] = $user['user_real_name'];
//                    $lists[$k]['user_create_id'] = $user['user_create_id'];
//                }
            
                $lists[$k]['member_type'] = session('cm_member_type');
            
            }
            $str = '';
            if($count2){
                $str = implode($count2,',');
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'count2' => $str, 'data' => $lists]);
        }
        
        $this->assign([
            'group' => $group,
            'lunci' => $lunci,
        ]);
        return $this->fetch('sailing/lsmark');
    }
    
    /**
     * 取消比赛
     * @return mixed|\think\response\Json
     */
    public function matchCancel(){
        $match_id = input('match_id');
        if(Request::instance()->isPost()){
            $match_cancel_reason = input('match_cancel_reason');
            $update = [
                'match_status' => 4,
                'match_cancel_reason' => $match_cancel_reason
            ];
            // 退款业务放在定时器中执行
            $res = Db::table('up_match')->where('match_id', $match_id)->update($update);
            if($res){
                return json(['code' => 200, 'msg' => '取消成功']);
            }else{
                return json(['code' => 100, 'msg' => '取消成功']);
            }
        }
        $this->assign('match_id', $match_id);
        return $this->fetch('sailing/matchcancel');
    }
    
    /**
     * 帆船起航数据
     * @return mixed|\think\response\Json
     */
    public function sailData(){
        $match_id = input('match_id');
        if(isset($match_id) && $match_id != ''){
            session('match_id', $match_id);
        }
        $match = Db::table('up_match')
            ->where('match_id', session('match_id'))
            ->field('match_lunci')
            ->find();
        $group = Db::table('up_match_apply_group')
            ->join('up_match_group', 'mg_id = mag_group_id', 'left')
            ->where('mag_match_id', session('match_id'))
            ->field('mg_id, mg_name')
            ->select();
        $lunci = range(1, $match['match_lunci']);
        if(request()->isAjax ()){
            $group_id = input('group_id'); //  组
            $lc_id = input('lc_id'); // 轮次
            $where['umd.match_id'] = session('match_id');
            if(isset($group_id) && $group_id != ''){
                $where['umd.level_id'] = $group_id;
            }
            /*else{
                $where['umd.level_id'] = $group[0]['mg_id'];
            }*/
            if(isset($lc_id) && $lc_id != ''){
                $where['umd.turn'] = $lc_id;
            }
            /*else{
                $where['umd.turn'] = $lunci[0];
            }*/
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $count2 = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->where($where)
                ->column('umar.id');// 获取总条数
            $lists = Db::table('up__match_arrive_record')
                ->alias('umar')
                ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
                ->field('umar.id, umd.match_id, umar.temp_score, umar.sensor_id, umd.turn, umar.start_line_time, 
                umar.start_line_location, umar.start_line_speed, umar.angle')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('umar.start_line_time asc')
                ->select();
            foreach($lists as $k => $v){
                // 名次
                $lists[$k]['mc'] = $k + 1;
                // 报名信息
                if($v['sensor_id']){
                    $sensor = explode('_', $v['sensor_id']);
                    $user = Db::table('up_u_user')
                        ->where('user_id', $sensor[1])
                        ->field('user_real_name')
                        ->find();
                    $apply = Db::table('up_match_apply_info')
                        ->join('up_club', 'ma_club_id = club_id', 'left')
                        ->where('ma_user_id', $sensor[1])
                        ->where('ma_match_id', $v['match_id'])
                        ->field('ma_fan_code, club_name')
                        ->find();
                    $lists[$k]['fan_code'] = $apply['ma_fan_code'];
                    $lists[$k]['club_name'] = $apply['club_name'];
                    $lists[$k]['user_real_name'] = $user['user_real_name'];
                }
            }
            $str = '';
            if($count2){
                $str = implode($count2,',');
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'count2' => $str, 'data' => $lists]);
        }
        
        $this->assign([
            'group' => $group,
            'lunci' => $lunci,
        ]);
        return $this->fetch('sailing/saildata');
    }
    
    /**
     * 导出临时成绩
     * @return \think\response\Json
     */
    public function outExcel(){
        set_time_limit(0);
        $ids = input('ids');
        if($ids == ''){
            return json(['code' => 100, 'msg' => '没有需要导出的数据']);
        }
        $lists = Db::table('up__match_arrive_record')
            ->alias('umar')
            ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
            ->join('up_match um', 'umd.match_id = um.match_id', 'left')
            ->join('up_match_group umg', 'umg.mg_id = umd.level_id', 'left')
            ->field('umar.id, umd.match_id, umar.temp_score, umar.sensor_id, ls_status, umd.turn, 
            um.match_title, umg.mg_name')
            ->where('umar.id', 'IN', $ids)
            ->order('umd.turn asc')
            ->select();
        foreach($lists as $k => $v){
            // 名次
            $lists[$k]['mc'] = $k + 1;
            // 报名信息
            $sensor = explode('_', $v['sensor_id']);
            $user = Db::table('up_u_user')
                ->where('user_id', $sensor[1])
                ->field('user_phone, user_real_name, user_create_id')
                ->find();
            $apply = Db::table('up_match_apply_info')
                ->where('ma_user_id', $sensor[1])
                ->where('ma_match_id', $v['match_id'])
                ->field('ma_fan_code')
                ->find();
            // 帆号
            $lists[$k]['fan_code'] = $apply['ma_fan_code'];
            // 真实姓名
            $lists[$k]['user_real_name'] = $user['user_real_name'];
            // 手机号
            $lists[$k]['user_phone'] = "\t".$user['user_phone']."\t";
            // 用户ID
            $lists[$k]['user_create_id'] = "\t".$user['user_create_id']."\t";
        }
        $cellname = [
            ['user_create_id', '用户ID', 15, 'LEFT'],
            ['user_real_name', '姓名', 15, 'LEFT'],
            ['user_phone', '手机号', 20, 'LEFT'],
            ['fan_code', '帆号', 15, 'LEFT'],
            ['temp_score', '成绩', 15, 'LEFT'],
            ['mc', '名次', 15, 'LEFT'],
            ['match_title', '赛事', 20, 'LEFT'],
            ['mg_name', '组别', 20, 'LEFT'],
            ['turn', '轮次', 15, 'LEFT'],
        ];
        $res = exportExcel('临时成绩表', 'lsMark', $cellname, $lists);
        return json($res);
    }
    
    /**
     * 导出起航数据
     * @return \think\response\Json
     */
    public function qhOutExcel(){
        set_time_limit(0);
        $ids = input('ids');
        if($ids == ''){
            return json(['code' => 100, 'msg' => '没有需要导出的数据']);
        }
        $lists = Db::table('up__match_arrive_record')
            ->alias('umar')
            ->join('up__match_detail umd', 'umar.match_detail_id = umd.id', 'left')
            ->join('up_match um', 'umd.match_id = um.match_id', 'left')
            ->join('up_match_group umg', 'umg.mg_id = umd.level_id', 'left')
            ->field('umar.id, umd.match_id, umar.temp_score, umar.sensor_id, umd.turn, umar.start_line_time, 
                umar.start_line_location, umar.start_line_speed, umar.angle, um.match_title, umg.mg_name')
            ->where('umar.id', 'IN', $ids)
            ->order('umar.start_line_time asc')
            ->select();
        foreach($lists as $k => $v){
            // 名次
            $lists[$k]['mc'] = $k + 1;
            // 报名信息
            $sensor = explode('_', $v['sensor_id']);
            $user = Db::table('up_u_user')
                ->where('user_id', $sensor[1])
                ->field('user_phone, user_real_name, user_create_id')
                ->find();
            $apply = Db::table('up_match_apply_info')
                ->join('up_club', 'ma_club_id = club_id', 'left')
                ->where('ma_user_id', $sensor[1])
                ->where('ma_match_id', $v['match_id'])
                ->field('ma_fan_code, club_name')
                ->find();
            // 代表队
            $lists[$k]['club_name'] = $apply['club_name'];
            // 帆号
            $lists[$k]['fan_code'] = $apply['ma_fan_code'];
            // 真实姓名
            $lists[$k]['user_real_name'] = $user['user_real_name'];
            // 手机号
            $lists[$k]['user_phone'] = "\t".$user['user_phone']."\t";
        }
        $cellname = [
            ['mc', '名次', 15, 'LEFT'],
            ['club_name', '代表队', 25, 'LEFT'],
            ['user_real_name', '姓名', 15, 'LEFT'],
            ['fan_code', '帆号', 15, 'LEFT'],
            ['start_line_time', '时间', 20, 'LEFT'],
            ['start_line_location', '位置', 15, 'LEFT'],
            ['start_line_speed', '速度', 15, 'LEFT'],
            ['angle', '角度', 15, 'LEFT'],
            ['match_title', '赛事', 20, 'LEFT'],
            ['mg_name', '组别', 20, 'LEFT'],
        ];
        $res = exportExcel('起航数据', 'setSail', $cellname, $lists);
        return json($res);
    }
}